package com.ruoyi.search.controller;


import com.ruoyi.DataManage.controller.UniversityController;
import com.ruoyi.DataManage.domain.*;
import com.ruoyi.DataManage.service.ICategoryService;
import com.ruoyi.DataManage.service.IExaminationCourseService;
import com.ruoyi.DataManage.service.ISubject_treeService;
import com.ruoyi.DataManage.service.IUniversityService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.search.domain.Search;
import com.ruoyi.search.domain.SearchVO;
import com.ruoyi.search.service.ISearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.parameters.P;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.core.page.TableDataInfo;

import java.util.List;

/**
 * 考研初试资源查询Controller
 *
 * @author CehnFneg
 * @date 2024-04-26
 */
@RestController
@RequestMapping("/search/search")

public class SearchController extends BaseController {

    @Autowired
    private IUniversityService universityService;

    @Autowired
    private ICategoryService categoryService;

    @Autowired
    private ISubject_treeService subject_treeService;

    @Autowired
    private IExaminationCourseService courseService;

    @Autowired
    private ISearchService searchService;

    /**
     * 获取省份列表
     * @return
     */
    @GetMapping("/provincelist")
    public AjaxResult getProvinceList()
    {
        List<Province> provinceList = universityService.getProvinceList();
        return AjaxResult.success(provinceList);
    }

    /**
     * 获取学校列表
     * @return
     */
    @GetMapping("/universitylist/{provinceId}")
    public AjaxResult getUniversityList(@PathVariable Long provinceId)
    {
        List<University> universityList = universityService.getUniversityListByProvinceId(provinceId);
        return AjaxResult.success(universityList);
    }

    /**
     * 获取门类列表
     * @return
     */
    @GetMapping("/categorylist/{universityId}")
    public AjaxResult getCategoryList(@PathVariable Long universityId)
    {
        List<Category> categoryList = categoryService.getCategoryList(universityId);
        return AjaxResult.success(categoryList);
    }

    /**
     * 获取学科列表
     * @return
     */
    @GetMapping("/subjectlist/{categoryId}")
    public AjaxResult getSubjectList(@PathVariable Long categoryId)
    {
        List<Subject_tree> subjectList = subject_treeService.getSubjectList(categoryId);
        return AjaxResult.success(subjectList);
    }

    /**
     * 获取专业列表
     * @return
     */
    @GetMapping("/majorlist/{subjectId}")
    public AjaxResult getMajorList(@PathVariable Long subjectId)
    {
        List<Subject_tree> subjectList = subject_treeService.getMajorListBySubjectId(subjectId);
        return AjaxResult.success(subjectList);
    }

    /**
     * 获取考试科目列表
     * @return
     */
    @GetMapping("/courselist/{majorId}")
    public AjaxResult getCourseList(@PathVariable Long majorId)
    {
        List<ExaminationCourse> courseList =  courseService.getCourseListByMajorId(majorId);
        return AjaxResult.success(courseList);
    }

    /**
     * 考研初试资源查询
     */
    @GetMapping("/list")
    public TableDataInfo list(Search search)
    {
        startPage();
        List<SearchVO> searchList = searchService.getSearchList(search);
        return getDataTable(searchList);
    }
}
